﻿using System;

using zijian666.Abstractions;
using zijian666.Convertor;
using zijian666.Core;

namespace zijian666.Factory;

/// <summary>
/// <seealso cref="ArrayConvertor{T}"/> 工厂
/// </summary>
public sealed class ArrayConvertorFactory : IConvertorFactory
{
    /// <inheritdoc />
    public MatchedConvertor<T> Create<T>()
    {
        var type = typeof(T);
        if (type.IsArray)
        {
            var convertor = (IConvertor<T>)Activator.CreateInstance(typeof(ArrayConvertor<>).MakeGenericType(type.GetElementType()));
            return new MatchedConvertor<T>(convertor, MacthedType.Equals);
        }
        return default;
    }
}
